package com.zlp.mall.upms.service.impl;

import com.alibaba.fastjson.JSON;
import com.zlp.mall.upms.entity.UserRole;
import com.zlp.mall.upms.mapper.UserRoleMapper;
import com.zlp.mall.upms.service.UserRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 用户角色表 服务实现类
 * </p>
 *
 * @author Zou.LiPing
 * @since 2021-04-06
 */
@Service
@RequiredArgsConstructor
@Slf4j(topic = "UserRoleServiceImpl")
public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRole> implements UserRoleService {

    @Override
    public void saveBatchRole(Integer userId,List<Integer> roidList) {

        log.info("saveBatchRole.req userId={},roidList={}",userId, JSON.toJSONString(roidList));
        List<UserRole> userRoleList = roidList.stream().map(roleId -> {
            UserRole userRole = new UserRole();
            userRole.setUserId(userId);
            userRole.setRoleId(roleId);
            return userRole;
        }).collect(Collectors.toList());
        this.saveBatch(userRoleList);
    }
}
